//Tue 16 Feb 2010 12:09:37 AM CST 
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class ColoringRectangle
{
public:
	int chooseDisks(int width, int height, vector <int> red, vector <int> blue)
	{
		sort(red.rbegin(), red.rend());
		sort(blue.rbegin(), blue.rend());
		double idx1 = 0.0;
		double idx2 = 0.0;
		int count1 = 0;
		int count2 = 0;
		bool flag1 = false;
		bool flag2 = false;
		int red1 = 0;
		int blue1 = 0;
		int red2 = 0;
		int blue2 = 0;
		while(idx1 <= 1.0*width && idx2 <= 1.0*width)
		{
			if(idx1 <= 1.0*width)
			{
				if(flag1)
				{
					idx1 += blue[blue1];
					blue1++;
					if(blue1 >= blue.size()) break;
				}
				else
				{
					idx1 += red[red1];
					red1++;
					if(red1 >= red.size()) break;
				}
				flag1 ^= true;
				count1++;
			}
			else
			{
				if(flag2)
				{
					idx2 += red[red2];
					red2++;
					if(red2 >= red.size()) break;
				}
				else
				{
					idx2 += blue[blue2];
					blue2++;
					if(blue2 >= blue.size()) break;
				}
				flag2 ^= true;
				count2++;
			}
		}
		int ret = min(count1, count2);
		return (ret==0 ? -1 : ret);
	}
};
